package com.example.demo.controller;

import com.example.demo.dao.StaffDao;
import com.example.demo.entity.Staff;
import com.example.demo.service.StaffService;
import com.example.demo.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: Tian
 * @version: 1.0
 * @since: 1.0
 * @date: 2024/4/17/19:13
 */
@RestController
@RequestMapping("/staff")
@Api(tags = "员工")
public class StaffController {

    @Autowired
    StaffService staffServiceImpl;

    @PostMapping("/selectAll/{current}/{pageSize}")
    @ApiOperation("【可以根据条件】查询所有员工信息")
    @ApiImplicitParams(
            value = {
                    @ApiImplicitParam(name="current",value = "当前页面",dataType = "int",required = true),
                    @ApiImplicitParam(name="pageSize",value = "每页的条数",dataType = "int",required = true),
                    @ApiImplicitParam(name = "staff",value = "查询条件",dataType = "Staff",required = true)
            }
    )
    public Result selectAll(@PathVariable Integer current, @PathVariable Integer pageSize,@RequestBody Staff staff){
        System.out.println(current);
        System.out.println(pageSize);
        System.out.println(staff==null);
        return staffServiceImpl.selectAll(current,pageSize,staff);
    }

    @ApiOperation("根据id查询员工信息")
    @GetMapping("/selectById/{id}")
    @ApiImplicitParam(name="id",value = "员工id",dataType = "int",required = true)
    public  Result selectById(@PathVariable Integer id){return staffServiceImpl.selectById(id);}

    @ApiOperation("根据id修改员工信息")
    @PutMapping("/updateStaff")
    @ApiImplicitParam(name = "staff",value = "修改的员工信息",dataType = "Staff",required = true)
    public  Result updateById(@RequestBody Staff staff){return staffServiceImpl.updateById(staff);}

    @ApiOperation("根据id删除员工")
    @DeleteMapping("/deleteStaff/{id}")
    @ApiImplicitParam(name="id",value = "员工id",dataType = "int",required = true)
    public  Result deleteById(@PathVariable Integer id){return staffServiceImpl.deleteById(id);}

    @ApiOperation("添加员工")
    @PostMapping("/add")
    @ApiImplicitParam(name = "staff",value = "修改的员工信息",dataType = "Staff",required = true)
    public Result insertStaff(@RequestBody Staff staff){
        return staffServiceImpl.insertStaff(staff);
    }
}
